import '@babel/polyfill';
// import promise from 'es6-promise';
import 'es6-promise/auto'
import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'font-awesome/css/font-awesome.min.css'
import './styles/public.scss';
import './styles/main.scss';
import './styles/form.scss';
import './styles/table.scss';
import './styles/button.scss';
import './styles/dialog.scss';
// import './styles/upload.scss';
import './styles/fontStyle.scss';
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
import routes from '@/router/routes'
import 'font-awesome/css/font-awesome.min.css'
import menuUtils from '@/utils/menuUtils';
import moment from 'moment';
import api from './index';
import './directive';
import './scrollLoad';
import infiniteScroll from 'vue-infinite-scroll';
import uploader from 'vue-simple-uploader'; //断点续传
import pageToolbar from '@/components/pageToolbar/pageToolbar.vue'
import md5 from 'js-md5';
Vue.prototype.$md5 = md5; // 全局引入MD5
// import Highlight from './utils/highlight/hightlight';
import {
    commonButton,
    confirmdelete,
    innerButton,
    imageButton,
    searchButton,
    editButton,
    deleteButton,
    commonDropDown,
    treeDropDown,
    trableDropDown,
    commonTable,
    commonSelect,
    commonTree,
    houseTree,
    anjuanTree,
    lazyTree,
    flyTree,
    commonDatePicker,
    dragPanel,
    commonTabs,
    commonMTabs,
    commonUpload,
    fileUpload,
    importUpload,
    layout,
    commonInput,
    dateInput,
    datetimeInput,
    timeInput,
    searchInput,
    // editInput,
    rangedateInput,
    importButton,
    pagetable,
    pageVxeTable,
    commonVxeTable,
    scrolltable,
    commonTreeTable,
    commonCheckbox,
    commonRadio,
    commonProgress,
    treeSelect,
    dropDown,
    cloudDiskTree,
    commonTree2,
    commonPdf,
    commonOfd,
    remoteInput,
    buttonInput,
    commonMapping,
    commonTooltip,
    commonWebSocket
} from "./common/components/common"

// 通用业务组件
import {
    commonTitle,
    commonToolbar,
    commonAreaToolbar
} from './common/views/common'
// 引入大数据表格 - 虚拟滚动
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
// import Vue2Editor from "vue2-editor";
// let Base64 = require('js-base64').Base64;
//promise.polyfill();


import "./common/style/messageBoxDialog.scss";
import "./common/style/operationIcon.scss";
/* 共通控件样式文件 */
import "./common/style/base.scss";
// import "./common/style/baseColor.scss";
let theme = localStorage.getItem('theme');
console.log(theme);
if(theme == 'default' || !theme){
    theme = '';
}
const modelpath = 'baseColor'+theme+'.scss';
const stylepath = 'style'+theme+'.scss';
import(`@/common/style/${modelpath}`).then(item => {})
import(`@/styles/theme/${stylepath}`).then(item => {})

import VXETablePluginMenus from 'vxe-table-plugin-menus'

import 'video.js/dist/video-js.css'
import "echarts/map/js/world.js";
import "echarts/map/js/china.js";
import "echarts/map/js/china-contour.js";
import "echarts/extension-src/bmap/bmap.js";
import "echarts/lib/component/legend";

VXETable.use(VXETablePluginMenus)
// const stylepath = 'baseColorTest.scss'
// import(`@/../static/css/${stylepath}`).then(item => {})

// let theme = localStorage.getItem('theme');
// if(!theme) {
//     import "./common/style/baseColor.scss";
// }else{
//     import "./common/style/baseColorTest.scss";
// }

Vue.component('pageToolbar', pageToolbar);

const components = [
    commonButton,
    confirmdelete,
    innerButton,
    imageButton,
    searchButton,
    editButton,
    deleteButton,
    commonDropDown,
    treeDropDown,
    trableDropDown,
    commonTable,
    commonSelect,
    dragPanel,
    commonTree,
    commonDatePicker,
    commonTabs,
    commonMTabs,
    layout,
    commonInput,
    searchInput,
    // editInput,
    dateInput,
    datetimeInput,
    timeInput,
    remoteInput,
    rangedateInput,
    buttonInput,
    importButton,
    pagetable,
    pageVxeTable,
    scrolltable,
    ElementUI,
    VueRouter,
    api,
    infiniteScroll,
    uploader,
    VXETable,
    // Vue2Editor,
    commonVxeTable,
    commonTreeTable,
    commonCheckbox,
    commonRadio,
    commonProgress,
    treeSelect,
    dropDown,
    // Highlight,
    commonTree2,
    //-------------------通用业务组件-------------------------//
    commonTitle,
    commonToolbar,
    commonAreaToolbar,
    commonTooltip,
]
components.forEach(com => {
    Vue.use(com);
})

if (!localStorage.getItem("token")) {
    routes[0].meta.requireAuth = true;
} else {
    routes[0].meta.requireAuth = false;
}

// 定义路由
const router = new VueRouter({
    mode: 'hash',
    routes
});
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}
// 定义全局时间过滤器
Vue.filter('dateFormat', function (value) {
    let date = value;
    if (date == undefined) {
        return "";
    }
    return moment(date).format("YYYY-MM-DD");
})
// 全局注册弹框信息
// 询问信息  
Vue.prototype.$askInformation = function (text, callback, callback2 = function () {
}, confirmButtonText = '确定', cancelButtonText = '取消') {
    this['$confirm'](text, '询问信息', {
        iconClass: 'askInformation',
        confirmButtonText: confirmButtonText,
        cancelButtonText: cancelButtonText,
        distinguishCancelAndClose:true, // 是否将取消（点击取消按钮）与关闭（点击关闭按钮或遮罩层、按下 ESC 键）进行区分
    }).then(() => {
        callback();
    }).catch((e) => {
        callback2(e)
    });
}
// 警示信息
Vue.prototype.$warningInformation = function (text, confirmButtonText = '知道了') {
    this['$confirm'](text, '警示信息', {
        iconClass: 'warningInformation',
        showCancelButton: false,
        confirmButtonText: confirmButtonText
    }).then(() => {
        // codeing
    });
}
// 成功信息
Vue.prototype.$successInformation = function (text, confirmButtonText = '确定') {
    this['$confirm'](text, '提示信息', {
        iconClass: 'successInformation',
        showCancelButton: false,
        confirmButtonText: confirmButtonText
    }).then(() => {
        // codeing
    });
}
// 后台成功提示信息
Vue.prototype.$backSuccessInformation = function (text, duration = 3000) {
    this['$notify']({
        title: '提示信息',
        message: text,
        iconClass: 'successInformation',
        position: 'bottom-right',
        duration: duration
    });
}
// 后台警示提示信息
Vue.prototype.$backWarningInformation = function (text, duration = 3000) {
    this['$notify']({
        title: '警示信息',
        message: text,
        iconClass: 'warningInformation',
        position: 'bottom-right',
        duration: duration
    });
}
// 后台错误提示信息
Vue.prototype.$backErrorInformation = function (text, duration = 3000) {
    this['$notify']({
        title: '错误信息',
        message: text,
        iconClass: 'errorInformation',
        position: 'bottom-right',
        duration: duration
    });
}
//elementui自带提示成功信息
Vue.prototype.$Suces = function (message) {
    this['$message']({
        type: 'success',
        message
    })
};
//elementui自带请求失败信息
Vue.prototype.$getError = function (message) {
    this["$message"]({
        message,
        type: 'error'
    });
};
//elementui自带警告信息
Vue.prototype.$Warn = function (message) {
    this['$message']({
        type: 'warning',
        message
    });
};
//elementui自带info信息
Vue.prototype.$info = function (message) {
    this['$message']({
        message: message,
        type: 'info'
    });
};

Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};


// 刷新重置路由
let data = JSON.parse(window.sessionStorage.getItem('menuData'));
window.sessionStorage.removeItem('auditFormData');
// window.sessionStorage.removeItem('basicForm');
window.sessionStorage.removeItem('auditDisplay');
window.sessionStorage.removeItem('auditSession');
window.sessionStorage.removeItem('examCheckArr');
window.sessionStorage.removeItem('addWay');

// 重置路由
if (data) {
    let routers = [];
    menuUtils(routers, data);
    router.addRoutes(routers);
}

router.beforeEach((route, redirect, next) => {
    let authOk = route.meta.requireAuth;

    next();
    return;
    if(authOk && route.path !== '/login/Login'){
        next({ path: '/login/Login'})
    }else if (route.path) {
        next();
    }else{
        next({ path: '/404'})
    }
});
// 挂载根实例
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app');

export default router
